﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;

namespace DTC.Converters
{
    [ValueConversion(typeof(DateTime), typeof(string))]
    public class DateTimeToDateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter,
            CultureInfo culture)
        {
            if (value == null)
                return "";
            DateTime date = (DateTime)value;
            if (date == new DateTime())
                return "";
            return date.ToString("d");
        }
        public object ConvertBack(object value, Type targetType, object parameter,
            CultureInfo culture)
        {
            string strdate = value.ToString();
            DateTime result;
            if (DateTime.TryParse(strdate, out result))
            {
                return result;
            }
            return value;
        }
    }
}
